home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / OOP.SWG / 0001_Execute a Popup Menu at ?.pas
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  1.8 KB  |  54 lines

  1. {
  2. >I'm new to Pascal and Turbo Vision and I am writing a program that
  3. >needs pop-up menus.  I've tried several times to use TMenuBox objects
  4. >but have had no luck at all.  Could someone please point me in the
  5. >right direction?  I am looking for a good Turbo Vision tutorial or a
  6. >short example using TMEnuBox with submenus from the first pop-up menu.
  7.  
  8. You can create popup menus using an instance of the TMenuPopup class.
  9. For a complete reference of this class have a look at the online help
  10. because the (german) manual doesn't describes TMenuPopup.
  11.  
  12. Use the following procedure to execute a popup menu:
  13. }
  14. procedure ExecutePopupMenu (At:TPoint; PopupMenu:PMenuPopup);
  15.   { shows the "PopupMenu" at the position "At" }
  16. var
  17.   Bounds : TRect;
  18.   D      : Integer;
  19. begin
  20.   if Application^.ValidView(PopupMenu) <> nil then
  21.   begin
  22.     D:=0;
  23.     Inc(At.Y);              
  24.     Application^.GetBounds(Bounds);
  25.     if At.Y + PopupMenu^.Size.Y > Bounds.B.Y then 
  26.     begin
  27.       Dec(At.Y, PopupMenu^.Size.Y+1);
  28.       if At.Y < Bounds.A.Y then
  29.       begin
  30.         At.Y:=Bounds.A.Y;
  31.         Inc(At.X); D:=1;
  32.       end;
  33.     end;
  34.     if At.X + PopupMenu^.Size.X > Bounds.B.X then    
  35.       Dec(At.X, PopupMenu^.Size.X+D);
  36.     Application^.MakeLocal(At, At);
  37.     PopupMenu^.MoveTo(At.X, At.Y);    
  38.     Application^.Insert(PopupMenu);   
  39.     Message(PopupMenu, evBroadcast, cmCommandSetChanged, nil);
  40.     Message(PopupMenu, evCommand, cmMenu, nil);
  41.     DisposeMenu(PopupMenu^.Menu);                
  42.     Dispose(PopupMenu, Done);
  43.   end;
  44. end;
  45.  
  46. Before executing the popup menu this procedure is doing some
  47. calculations to guarantee that regardless of the parameter "At" the
  48. popup menu is always showed within the current screen boundaries of
  49. "Application".
  50.  
  51. - Kai
  52.  
  53.  
  54.